package com.horay.springbootdemo.session.redis.index.controller;

import com.horay.springbootdemo.common.result.ResultBody;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Objects;
import java.util.UUID;

/**
 * 首页控制器
 *
 * @author heyingcheng
 * @date 2019/10/1 16:45
 */
@Slf4j
@RestController
@RequestMapping("session")
public class IndexController {

    @GetMapping("index")
    public ResultBody<String> index(HttpSession session) {
        Object userInfo = session.getAttribute("UserInfo");
        if (Objects.nonNull(userInfo)) {
            log.info("IndexController.index.userInfo:[{}]", userInfo);
        } else {
            session.setAttribute("UserInfo", UUID.randomUUID().toString());
        }
        return ResultBody.RESULT_BODY_SUCCESS;
    }

}
